home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / procssng / ccs / ccs-11tl.lha / lbl / x11 / lib / x_window.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-01-16  |  4.0 KB  |  143 lines

  1. /*    X_WINDOW . C
  2. %
  3. %    Copyright (c)    Jin, Guojun
  4. %
  5. %    void    DumpScan_to_dpy(img)
  6. %    handle_exposure(img, sub_win, x, y, width, height, img_h)
  7. %
  8. %        # the connection with map_scan.c #
  9. %    Map_Scanline(img, data_buf, save_scan, x0, y, w, icon_factor)
  10. %    Maintain_Flush(img, previous, imgp, image_y)
  11. %    MapRGB(img, prev_img, imgp, data_buf, save_scan, max_h-y, w, y, icn_fact)
  12. %
  13. % AUTHOR:    Jin Guojun - LBL    8/1/91
  14. */
  15.  
  16. #include "panel.h"
  17. #include "imagedef.h"
  18.  
  19.  
  20. void
  21. DumpScan_to_dpy(img)    /* dump entire image to the screen */
  22. image_information*    img;
  23. {
  24. byte    *read_scan[3], *save_scan[3];
  25. register int    i, y=img->h, ifactor = get_iconsize(img, 0);
  26.     while (y--){
  27.         read_scan[0] = ORIG_RLE_ROW(img, y);
  28.         save_scan[0] = SAVED_RLE_ROW(img, y);
  29.         for (i=1; i < img->img_channels; i++)
  30.             read_scan[i] = read_scan[i-1] + img->w,
  31.             save_scan[i] = save_scan[i-1] + img->w;
  32.         Map_Scanline(img, read_scan, save_scan, 0, y, img->w, ifactor);
  33.     }
  34.     i = strlen(img->name) + sizeof(HELP_INFO) + 8;
  35.     if (pointer_buffer_size(img->title) < i)
  36.         img->title = (char *)realloc(img->title, i);
  37.     sprintf(img->title, "%s(%d) %s", img->name, img->RGB, HELP_INFO);
  38.     XStoreName(img->dpy, img->window, img->title);
  39.     XPutImage(img->dpy, img->window, img->gc, img->image,
  40.         0, 0, 0, 0, img->w, img->h);
  41.     if (img->refresh_pixmap)
  42.         XCopyArea(img->dpy, img->window, img->refresh_pixmap, img->gc,
  43.         0, 0, img->w, img->h, 0, 0);
  44. }
  45.  
  46. void
  47. handle_exposure(img, sub_win, x, y, width, height, img_h, tuner_flag)
  48. register image_information    *img;
  49. int    (*sub_win)();
  50. {
  51. register int    x0, y0;
  52.     /*
  53.     * If window has been resized (bigger), dont bother redrawing
  54.     * the area outside the image.
  55.     */
  56.     if (x < 0)
  57.         width -= x,    x = 0;
  58.  
  59. /*    if the image has not yet read itself in, dont blit any of it
  60.     instead clear out that top portion of the window (not needed oh well)
  61. */
  62.     if (y < img->h - img_h && img->in_type==RLE)    {
  63.         XClearArea(img->dpy, img->window, x, y,
  64.             width, img->h - img_h - y, False);
  65.         height -= img->h - img_h - y;
  66.         y = img->h - img_h;
  67.     }
  68.  
  69.     if (height < 1)    return;    /* hardly happen */
  70.  
  71.     if (y + height >= img->h)
  72.         height = img->h - y;
  73.  
  74.     /*    if bitmap, round beginning pixel to beginning of word    */
  75.  
  76.     if (img->binary_img) {
  77.         int offset = x % BitmapPad(img->dpy);
  78.         x -= offset;
  79.         width += offset;
  80.     }
  81.     if (x + width >= img->w)
  82.         width = img->w - x;
  83.  
  84.     if (width < 1 || height < 1)    return;
  85.  
  86.     exposure_r(img, sub_win, x, y, width, height, True);
  87. }
  88.  
  89.  
  90. Map_Scanline(img, data_buf, save_scan, x0, y, w, icon_factor)
  91. image_information*    img;
  92. byte    *data_buf[], *save_scan[];
  93. {
  94. if (img->mono_img)    /*    map  data_buf to save_scan    */
  95.     map_rgb_to_bw(img, data_buf, save_scan[0], w);    /* 0 = img->w */
  96. else
  97.     map_rgb_to_rgb(img, data_buf, save_scan, w);
  98.  
  99.     /*    map save_scan (1 line, width `w') to img->image->data    */
  100. (*img->map_scanline)(img, save_scan, img->dpy_channels, w, 1, y, x0, img->image);
  101.  
  102.     /* Subsample image to create icon */
  103. if (img->icn_image && (y%icon_factor == 0))
  104.     (*img->map_scanline)(img, save_scan, img->dpy_channels,
  105.          img->icn_w, icon_factor, y / icon_factor, 0, img->icn_image);
  106. if (img->in_type==RLE)    y--;    else    y++;
  107. return    y;
  108. }
  109.  
  110. Maintain_Flush(cur_img, previous, imgp, image_y)
  111. image_information    *previous, **imgp;
  112. {
  113. XEvent event;
  114. image_information    *img = imgp[cur_img];
  115.  
  116.     while (XPending(img->dpy)) {
  117.     XNextEvent(img->dpy, &event);
  118.     if (event.type == Expose) {
  119.         image_information *eimg;
  120.         register int     i;
  121.         /* get the right window bro....  */
  122.         i = WhichImage(event.xany.window, imgp, cur_img);
  123.         if (previous || i<0)
  124.             eimg = imgp[cur_img];    /*flip_book override */
  125.         else    eimg = imgp[i];
  126.         handle_exposure(eimg, Draws, event.xexpose.x, event.xexpose.y,
  127.             event.xexpose.width, event.xexpose.height,
  128.             (i==cur_img) ? (img->in_type==RLE) ? image_y :
  129.             img->h-image_y : eimg->h);
  130.         XFlush(img->dpy);
  131.     }
  132.     }
  133. }
  134.  
  135. MapRGB(cur_img, previous, imgp, data_buf, save_scan, y, w, image_y, icon_factor)
  136. image_information    *previous, **imgp;
  137. byte    *data_buf[], *save_scan[];
  138. {
  139. y = Map_Scanline(imgp[cur_img], data_buf, save_scan, 0, y, w, icon_factor);
  140. Maintain_Flush(cur_img, previous, imgp, image_y);
  141. return    y;
  142. }
  143.